import request from '@/utils/request';

export async function queryRule(params) {
  let obj = {
    page: params.current,
    limit: params.pageSize,
  };
  Object.assign(params, obj);
  delete params.current;
  delete params.pageSize;
  return request('/goods/goods/page', {
    params,
  });
}
export async function TemporaryRule(params) {
  return request('/goods/goods/page/expire', {
    params,
  });
}
export async function removeRule(params) {
  return request(`goods/goods/${params}`, {
    method: 'DELETE',
  });
}
export async function addRule(params) {
  return request('/goods/goods', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}
export async function updateRule(params) {
  return request('/goods/goods', {
    method: 'PUT',
    data: {
      ...params,
    },
  });
}
export async function updateCommodity(params) {
  return request(`goods/goods/${params.id}-${params.status}`, {
    method: 'PUT',
  });
}

export async function BrandRule(params) {
  return request('/goods/goodsBrand/list', {
    params,
  });
}
export async function ClassRule(params) {
  return request('/goods/goodsCategory/list?parent=true', {
    params,
  });
}
export async function getCommodityDetails(params) {
  return request(`/goods/goods/${params}`, {
    params,
  });
}

export async function querySales(params, goodsId) {
  return request(`/pay/order/goods/${goodsId}`, {
    params,
  });
}
export async function exportCommodity({
  goodsItemId,
  storeId
}) {
  return request(`/goods/import/export?storeId=${storeId}`, {
    method: 'GET',
    responseType: 'blob',
  });
}
export async function getStore(params) {
  return request('store/store/list', {
    params,
  });
}
export async function exportRefund(params) {
  return request(
    `goods/goodsItemStockRecord/export`, {
      params,
      method: 'GET',
      responseType: 'blob'
    },
  );
}
